package cn.yougou.common;

import cn.yougou.vo.YgResCommodityVo;

import java.math.BigDecimal;
import java.util.List;

/**
 * 计算业务工具类
 */
public class CalculateUtil {

    /**
     * 计算折扣价
     * @return
     */
    public static double getPrice(double price,double discount){
        //将价格四舍五入到小数点后一位
        return new BigDecimal(
                price*(discount/10)
        ).setScale(
                1,BigDecimal.ROUND_HALF_UP
        ).doubleValue();
    }

    /**
     * 计算好评率
     * @param count
     * @param part
     * @return
     */
    public static String getPercent(double part,int count){
        Integer percent = (int) Math.round(part/count*100);
        //加上百分号
        String goodsString = percent.toString()+"%";
        return goodsString;
    }


    /**
     *计算平均优惠价格
     * @return
     */
    public static double getApportionPrice(double money,  List<YgResCommodityVo> getjudge ){
       int count =geiCount(getjudge);
       return new BigDecimal(money/count).setScale(2,BigDecimal.ROUND_DOWN).doubleValue();
    }
/**
 * 计算总件数
 * */
   public static int geiCount(  List<YgResCommodityVo> getjudge ) {
       int count = 0;
       if(!getjudge.isEmpty()){
           for (YgResCommodityVo com : getjudge){
               count+=com.getCommodityCount();
           }
       }
       return count;
   }
    /**
     * 计算优惠总金额
     * @param price
     * @param disPrice
     * @param number
     * @return
     */
    public static double getDiscount(double price,double disPrice,int number){
         //原价减去折扣价 乘以件数 得出该商品优惠总金额
         double discountMoney  = (price - disPrice)*number;
         return new BigDecimal(discountMoney).setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();
    }


}
